package com.liu.stockmarket.ui.statistics.adapter

import android.view.View
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.cardview.widget.CardView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.liu.stockmarket.R
import com.liu.stockmarket.model.Stock
import com.liu.stockmarket.utils.getString
import com.liu.stockmarket.utils.money
import java.math.BigDecimal
import java.time.LocalDate

class CalendarAdapter : BaseQuickAdapter<CalendarAdapter.Item, BaseViewHolder>(
    R.layout.item_profit_calendar
), LoadMoreModule {


    override fun convert(holder: BaseViewHolder, item: Item) {
        holder.setVisible(R.id.rl_container, item.isShow)
        holder.setGone(R.id.tv_profit, item.isTitle)

        holder.setText(R.id.tv_date, item.title)
            .setTextColor(
                R.id.tv_date,
                if (item.isTitle) context.getColor(R.color.gray_double) else context.getColor(R.color.white)
            )
            .setText(R.id.tv_profit, item.profit?.getString(0) ?: "")

        val container = holder.getView<View>(R.id.rl_container)
        val profit = holder.getView<TextView>(R.id.tv_profit)
        val title = holder.getView<TextView>(R.id.tv_date)
        title.setTextColor(context.getColor(R.color.btn_text_color))
        if (item.profit == null || item.profit.setScale(
                2,
                BigDecimal.ROUND_CEILING
            ) == BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_CEILING)
        ) {

            container.setBackgroundColor(context.getColor(R.color.white))
            profit.visibility = View.GONE
            title.setTextColor(context.getColor(R.color.black))
        } else if (item.profit.setScale(2, BigDecimal.ROUND_CEILING) > BigDecimal.ZERO.setScale(
                2,
                BigDecimal.ROUND_CEILING
            )
        ) {
            container.setBackgroundColor(context.getColor(R.color.up))
        } else {
            container.setBackgroundColor(context.getColor(R.color.down))
        }


    }

    data class Item(
        val isTitle: Boolean,
        val isShow: Boolean,
        val title: String? = null,
        val date: LocalDate? = null,
        val profit: BigDecimal? = null,
    )
}